go fishing for an existing fish for the source/destination combination
authorØyvind Kolås <ok@src.gnome.org>
Mon, 12 Mar 2007 01:40:39 +0000 (01:40 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Mon, 12 Mar 2007 01:40:39 +0000 (01:40 +0000)
* babl/babl-fish.c: (fishing_result_examine), (go_fishing),
(babl_fish): go fishing for an existing fish for the
source/destination combination before trying to create one.

svn path=/trunk/; revision=226

ChangeLog
babl/babl-fish.c

index 99423947b450d8b2a7663ed1627c7610e88f7890..408fd8ccc49583cb5fd2cb3a43bfd6f44fc98d25 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-03-12  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/babl-fish.c: (fishing_result_examine), (go_fishing),
+       (babl_fish): go fishing for an existing fish for the
+       source/destination combination before trying to create one.
+
 2007-02-22  Øyvind Kolås  <pippin@gimp.org>
 
        * babl/babl-classes.h: make _Babl be a typedef and not a union that
index cb5a3021d405d02d4dd545c3f7833b5d4ba1d6c5..c01de2a9abf82ace3314c59798a846e7b32c9d75 100644 (file)
@@ -56,6 +56,58 @@ babl_fish_db (void)
   return db;
 }
 
+typedef struct BablFishingData
+{
+  Babl *source;
+  Babl *destination;
+  Babl *ret;
+} BablFishingData;
+
+static int 
+fishing_result_examine (Babl *babl,
+                        void *void_data)
+{
+  BablFishingData *data = void_data;
+
+  if ((void*)data->source == (void*)babl->fish.source &&
+      (void*)data->destination == (void*)babl->fish.destination)
+    {
+          data->ret = babl;
+          return 1; /* stop iterating */
+    }
+  return 0;  /* continue iterating */
+}
+
+static int yes=0;
+static int no=0;
+
+static Babl * 
+go_fishing (Babl    *source,
+            Babl    *destination)
+{
+  {
+    BablFishingData data;
+
+    data.source = source;
+    data.destination = destination;
+    data.ret = NULL;
+
+
+    babl_db_each (db, fishing_result_examine, &data);
+
+    if (data.ret != NULL)
+      {
+        yes++;
+      }
+    else
+      {
+        no++;
+      }
+
+    return data.ret;
+  }
+}
+
 Babl *
 babl_fish (void *source,
            void *destination,
@@ -98,7 +150,13 @@ babl_fish (void *source,
       babl_log ("args=(%p, %p) destination format invalid", source, destination);
       return NULL;
     }
+
+    {
+  Babl *lucky;
+  lucky = go_fishing (source_format, destination_format);
+  if (lucky)
+    return lucky;
+    }
  
   if (0)
     {
@@ -113,7 +171,6 @@ babl_fish (void *source,
       }
   }
 
-
   {
     Babl *fish_path;